<?php
/**
 * Zend Framework
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://framework.zend.com/license/new-bsd
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@zend.com so we can send you a copy immediately.
 *
 * @category  Zend
 * @package   Zend_DataGrid
 * @subpackage Column
 * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
 * @license   http://framework.zend.com/license/new-bsd     New BSD License
 */

/** @see Zend_DataGrid_Column */
require_once 'Zend/DataGrid/Column.php';



/**
 * Zend_DataGrid_Column_Template
 * The template column customizes rendering in the column with templates. In particular,
 * you can specify the item, edit item, header and footer template to customize the column.
 *
 * @category   Zend
 * @package    Zend_DataGrid
 * @subpackage Column
 * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
 * @license   http://framework.zend.com/license/new-bsd     New BSD License
 * @version   $Id: Template.php 6137 2008-09-13 17:37:27Z azoungrana $
 */
class Zend_DataGrid_Column_Template extends Zend_DataGrid_Column
{
    /**
     * The content of edit item template or the path to the partial
     *
     * @var string
     */
    protected $_editItemTemplate=null;

    /**
     * The content of footer template or the path to the partial
     *
     * @var string
     */
    protected $_footerTemplate=null;

    /**
     * The content of header template or the path to the partial
     *
     * @var string
     */
    protected $_headerTemplate=null;

    /**
     * The content of item template or the path to the partial
     *
     * @var string
     */
    protected $_itemTemplate=null;

    /**
     * Detect if its content or template path and load it
     *
     * @param string $value
     */
    private function _getTemplate($value)
    {
        //load if it is path
        if (is_file($value)) {
            $content = file_get_contents($value);
            return $content;
        }

        return $value;
    }

    /**
     * Sets the edit item template
     *
     * @param string $value the content or the partial path
     * @return Zend_DataGrid_Column_Template
     */
    public function setEditItemTemplate($value)
    {
        $this->_editItemTemplate = $this->_getTemplate($value);
        return $this;
    }

    /**
     * Gets the edit item template
     *
     * @return string
     */
    public function getEditItemTemplate()
    {
        return $this->_editItemTemplate;
    }

    /**
     * Sets the footer template
     *
     * @param string $value the content or the partial path
     * @return Zend_DataGrid_Column_Template
     */
    public function setFooterTemplate($value)
    {
        $this->_footerTemplate = $this->_getTemplate($value);
        return $this;
    }

    /**
     * Gets the footer template
     *
     * @return string
     */
    public function getFooterTemplate()
    {
        return $this->_footerTemplate;
    }

    /**
     * Sets the header template
     *
     * @param string $value the content or the partial path
     * @return Zend_DataGrid_Column_Template
     */
    public function setHeaderTemplate($value)
    {
        $this->_headerTemplate = $this->_getTemplate($value);
        return $this;
    }

    /**
     * Gets the header template
     *
     * @return string
     */
    public function getHeaderTemplate()
    {
        return $this->_headerTemplate;
    }

    /**
     * Sets the item template
     *
     * @param string $value the content or the partial path
     * @return Zend_DataGrid_Column_Template
     */
    public function setItemTemplate($value)
    {
        $this->_itemTemplate = $this->_getTemplate($value);
        return $this;
    }

    /**
     * Gets the item template
     *
     * @return string
     */
    public function getItemTemplate()
    {
        return $this->_itemTemplate;
    }



}
